<template>
  <a-modal
    :title="title"
    :width="460"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="取消"
    okText="保存"
    wrapClassName="ant-modal-cust-warp">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="定制项名称">
          <a-input placeholder="请输入定制项名称" v-model="category_name"/>
        </a-form-item>

<!--        <a-form-item-->
<!--          :labelCol="labelCol"-->
<!--          :wrapperCol="wrapperCol"-->
<!--          label="角色编码">-->
<!--          <a-input placeholder="请输入角色编码" :disabled="roleDisabled" v-decorator.trim="[ 'roleCode', validatorRules.roleCode]" />-->
<!--        </a-form-item>-->

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="设置排序"
          hasFeedback >
          <a-input placeholder="请输入定制项排列序号" v-model="category_num"/>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注"
          hasFeedback >
          <a-textarea placeholder="请输入定制项备注信息" v-model="remark" rows="5"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction, postAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "JeecgDemoModal",
    components: {
    },
    data () {
      return {
        category_name:'',
        category_num:'0',
        remark:'',
        dataDetail:[],//数据对象
        title:"操作",
        visible: false,
        model: {},
        validatorRules:{
          roleName:{
            rules: [
              { required: true, message: '请输入角色名称!' },
              { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }
            ]},
          roleCode:{
            rules: [
              { required: true, message: '请输入角色名称!'},
              { min: 0, max: 64, message: '长度不超过 64 个字符', trigger: 'blur' },
              { validator: this.validateRoleCode}
            ]},
          description:{
            rules: [
              { min: 0, max: 126, message: '长度不超过 126 个字符', trigger: 'blur' }
            ]}
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        couponList: [
          {
            id: '54,55',
            name: '全部'
          },
          {
            id: '54',
            name: '男装'
          },
          {
            id: '55',
            name: '女装'
          }
        ],
        categoryList: [],
        confirmLoading: false,
        form: this.$form.createForm(this),
        url: {
          query_detail:"/admin/parameter/query_dingzhiBydingzhiId",
          add: "/admin/parameter/add_dingzhi",
          edit: "/admin/parameter/update_dingzhi",
          query_dingzhiList:"/admin/parameter/query_dingzhiBypingleiId",
        },
      }
    },
    computed: {

    },
    created () {

    },
    methods: {
      edit (record) {
        this.category_name='';
        this.category_num='0';
        this.remark='';
        this.model = Object.assign({}, record);
        this.visible = true;//开启弹框
        if(record=="0"){
          // alert(this.$route.query.category_id)
          this.title="新增定制项"
        }else {
          this.title="编辑定制项"
          this.show_datainfodetail(this.model.id);
        }
      },
      show_datainfodetail(id) {
        let params = {dinghzi_id:id};
        getAction(this.url.query_detail,params).then((res)=>{
          console.info(res);
          if(res.success){
            this.dataDetail = res.result;
            this.category_name=this.dataDetail.parameter;
            this.category_num=this.dataDetail.numbers;
            this.remark=this.dataDetail.remark;
          }else {
            this.$message.error("查询失败2");
          }
        });
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if(this.category_name==null || this.category_name==''){
            this.$message.warning("请输入定制项名称");
            return;
          }else if(this.category_num=='' || this.category_num==null){
            this.$message.warning("请选择排序");
            return;
          }
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            let params = '';
            if(this.model.id!=null && this.model.id!=''){
              httpurl+=this.url.edit;
              method = 'put';
              params = {parameter:this.category_name,remark:this.remark,
                numbers:this.category_num,id:this.model.id}
            }else{
              httpurl+=this.url.add;
              method = 'post';
              params = {parameter:this.category_name,remark:this.remark,
                numbers:this.category_num,categoryId:this.$route.query.category_id}
            }
            httpAction(httpurl,params,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>

<style scoped>

</style>